package com.jianguo.web.controller.api;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jianguo.companion.domain.PzCompanion;
import com.jianguo.companion.service.IPzCompanionService;
import com.jianguo.order.domain.PzOrder;
import com.jianguo.user.domain.PzUser;
import com.jianguo.user.domain.PzUserAddress;
import com.jianguo.user.service.IPzUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianguo.common.annotation.Log;
import com.jianguo.common.core.controller.BaseController;
import com.jianguo.common.core.domain.AjaxResult;
import com.jianguo.common.enums.BusinessType;
import com.jianguo.companion.domain.PzIdentify;
import com.jianguo.companion.service.IPzIdentifyService;
import com.jianguo.common.utils.poi.ExcelUtil;
import com.jianguo.common.core.page.TableDataInfo;

/**
 * 实名认证Controller
 *
 * @author hxq
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/api/companion/identify")
public class IdentifyApi extends BaseController {
    @Autowired
    private IPzIdentifyService pzIdentifyService;

    @Autowired
    private IPzCompanionService pzCompanionService;

    /**
     * 新增实名认证
     */

    @PostMapping("/add")
    public AjaxResult add(@RequestBody PzIdentify pzIdentify) {
        pzIdentify.setStatus(1L);
        return toAjax(pzIdentifyService.save(pzIdentify));
    }


    /**
     * 获取实名认证
     */
    @GetMapping(value = "/info")
    public AjaxResult getInfo(String user) {
        Long status = 0L;
        LambdaQueryWrapper<PzIdentify> queryWrapper = new LambdaQueryWrapper<PzIdentify>()
                .eq(PzIdentify::getUser, user);
        PzIdentify one = pzIdentifyService.getOne(queryWrapper);
        // 如果为空说明未实名
        if (!ObjectUtil.isEmpty(one)) {
            status = one.getStatus();
        }

        return success(status);
    }

    @GetMapping(value = "/check")
    public AjaxResult getInfo(HttpServletRequest request) {
        String account = request.getHeader("account");

        Long status = 0L;
        LambdaQueryWrapper<PzIdentify> queryWrapper = new LambdaQueryWrapper<PzIdentify>()
                .eq(PzIdentify::getRemark, account);
        PzIdentify one = pzIdentifyService.getOne(queryWrapper);
        // 如果为空说明未实名
        if (!ObjectUtil.isEmpty(one)) {
            status = one.getStatus();
        }


        return success(status);
    }


}
